package com.itsu.service;

import com.itsu.compoment.socket.Message;
import com.itsu.dao.MessageDAO;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

/**
 * @author 苏犇
 * @create time 2019/12/6 23:47
 */
@Service
public class MessageService {

    @Resource
    private MessageDAO messageDAO;

    @Resource
    private RabbitTemplate rabbitTemplate;

    @Transactional(rollbackFor = Throwable.class)
    public void saveOne(Message message) {
        messageDAO.insert(message);
    }

    public void sendToQueue(Message message) {
        rabbitTemplate.convertAndSend("socket.msg.push", message);
    }

}
